<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px" >
      <el-form-item label="入住单号" prop="checkInNo" style="width: 240px">
        <el-input
          v-model="queryParams.checkInNo"
          placeholder="请输入入住单号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="老人姓名" prop="elderlyName" :label-width="100" style="width: 230px">
        <el-input
          v-model="queryParams.elderlyName"
          placeholder="请输入老人姓名"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="老人身份证号" prop="elderIdCard" :label-width="100">
        <el-input
          v-model="queryParams.elderIdCard"
          placeholder="请输入老人身份证号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入住开始时间" style="width: 308px" :label-width="120">
        <el-date-picker
          v-model="daterangeCheckInStartTime"
          value-format="YYYY-MM-DD"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['le:checkinmanagement:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['le:checkinmanagement:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['le:checkinmanagement:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['le:checkinmanagement:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          @click="handleRuZhu"
        >发起入住申请</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="primary"
          @click="handleRuZhu1"
        >发起入住申请</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="checkinmanagementList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="id" />
      <el-table-column label="入住单号" align="center" prop="checkInNo" />
      <el-table-column label="老人姓名" align="center" prop="elderlyName" />
      <el-table-column label="老人身份证号" align="center" prop="elderIdCard" />
      <el-table-column label="床位号" align="center" prop="bedNo" />
      <el-table-column label="入住开始时间" align="center" prop="checkInStartTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.checkInStartTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="nickName" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['le:checkinmanagement:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['le:checkinmanagement:remove']">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改入住办理对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="checkinmanagementRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="入住单号" prop="checkInNo">
          <el-input v-model="form.checkInNo" placeholder="请输入入住单号" />
        </el-form-item>
        <el-form-item label="老人外键编号" prop="elderlyId">
          <el-input v-model="form.elderlyId" placeholder="请输入老人外键编号" />
        </el-form-item>
        <el-form-item label="入住开始时间" prop="checkInStartTime">
          <el-date-picker clearable
            v-model="form.checkInStartTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择入住开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="入住预结束时间" prop="checkInEndTime">
          <el-date-picker clearable
            v-model="form.checkInEndTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择入住预结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建人" prop="creator">
          <el-input v-model="form.creator" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="护理等级外键编号" prop="nursingLevelId">
          <el-input v-model="form.nursingLevelId" placeholder="请输入护理等级外键编号" />
        </el-form-item>
        <el-form-item label="入住床位外键编号" prop="bedId">
          <el-input v-model="form.bedId" placeholder="请输入入住床位外键编号" />
        </el-form-item>
        <el-form-item label="费用期限开始时间" prop="feeStartDate">
          <el-date-picker clearable
            v-model="form.feeStartDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择费用期限开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="费用期限结束时间" prop="feeEndDate">
          <el-date-picker clearable
            v-model="form.feeEndDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择费用期限结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="押金" prop="deposit">
          <el-input v-model="form.deposit" placeholder="请输入押金" />
        </el-form-item>
        <el-form-item label="护理费用" prop="nursingFee">
          <el-input v-model="form.nursingFee" placeholder="请输入护理费用" />
        </el-form-item>
        <el-form-item label="床位费用" prop="bedFee">
          <el-input v-model="form.bedFee" placeholder="请输入床位费用" />
        </el-form-item>
        <el-form-item label="其他费用" prop="otherFee">
          <el-input v-model="form.otherFee" placeholder="请输入其他费用" />
        </el-form-item>
        <el-form-item label="医保支付" prop="medicalInsurancePayment">
          <el-input v-model="form.medicalInsurancePayment" placeholder="请输入医保支付" />
        </el-form-item>
        <el-form-item label="政府补贴" prop="governmentSubsidy">
          <el-input v-model="form.governmentSubsidy" placeholder="请输入政府补贴" />
        </el-form-item>
        <el-form-item label="业务ID" prop="businessId">
          <el-input v-model="form.businessId" placeholder="请输入业务ID" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Checkinmanagement">
import { listCheckinmanagement, getCheckinmanagement, delCheckinmanagement, addCheckinmanagement, updateCheckinmanagement,  } from "@/api/le/checkinmanagement"
import {useRouter} from 'vue-router'
const router = useRouter()
function handleRuZhu() {
  router.push({
    path: '/xietong/shenqing/ru/rzxq',
  })
}
function handleRuZhu1() {
  router.push({
    path: '/le/ruzhuxq/processEntry',
  })
}


const { proxy } = getCurrentInstance()

const checkinmanagementList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")
const daterangeCheckInStartTime = ref([])

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    checkInNo: null,
    elderlyId: null,
    checkInStartTime: null,
  },
  rules: {
  }
})

const { queryParams, form, rules } = toRefs(data)

/** 查询入住办理列表 */
function getList() {
  loading.value = true
  queryParams.value.params = {}
  if (null != daterangeCheckInStartTime && '' != daterangeCheckInStartTime) {
    queryParams.value.params["beginCheckInStartTime"] = daterangeCheckInStartTime.value[0]
    queryParams.value.params["endCheckInStartTime"] = daterangeCheckInStartTime.value[1]
  }
  listCheckinmanagement(queryParams.value).then(response => {
    checkinmanagementList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 取消按钮
function cancel() {
  open.value = false
  reset()
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    checkInNo: null,
    elderlyId: null,
    checkInStartTime: null,
    checkInEndTime: null,
    creator: null,
    createTime: null,
    nursingLevelId: null,
    bedId: null,
    feeStartDate: null,
    feeEndDate: null,
    deposit: null,
    nursingFee: null,
    bedFee: null,
    otherFee: null,
    medicalInsurancePayment: null,
    governmentSubsidy: null,
    businessId: null,
    extraField1: null,
    extraField2: null,
    elderlyName: null,
    elderIdCard: null,
    bedNo: null,
    nickName: null,
  }
  proxy.resetForm("checkinmanagementRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  daterangeCheckInStartTime.value = []
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  open.value = true
  title.value = "添加入住办理"
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _id = row.id || ids.value
  getCheckinmanagement(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改入住办理"
  })
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["checkinmanagementRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateCheckinmanagement(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addCheckinmanagement(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value
  proxy.$modal.confirm('是否确认删除入住办理编号为"' + _ids + '"的数据项？').then(function() {
    return delCheckinmanagement(_ids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => {})
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('le/checkinmanagement/export', {
    ...queryParams.value
  }, `checkinmanagement_${new Date().getTime()}.xlsx`)
}



getList()
</script>
